function setup() {
  createCanvas(700, 700); pixelDensity(1); 
}

let xmin = -2.2
let xmax = 1.7
let ymin = -2.2
let ymax = 1.7

function draw() {
  colorMode(HSB, 255)
let maxiter = 150
 loadPixels() 
  for(let x =0; x < width; x++){
    for(let y = 0; y < height; y++){
      let a = map(x, 0, width, xmin, xmax)
      let b = map(y, 0, height, ymin, ymax)
      
      let ca = a
      let cb = b
      let n = 0
      while(n < maxiter){ 
        let aa = a**2 - b**2
        let bb = 2 * a * b
        a = aa + ca 
        b = bb + cb
        
        if(a*a + b*b > 20){
          break
        }
         n++ 
      }
      var bright = map(n, 0, maxiter, 0, 1);
      bright = map(bright, 0, 1, 0, 255);
      bright = color(cos(bright), bright, bright*3)

      if (n == maxiter) {
        bright = 0;
      }

      var pixel = (x + y * width) * 4;
      pixels[pixel + 0] = hue(bright);
      pixels[pixel + 1] = saturation(bright);
      pixels[pixel + 2] = lightness(bright);
      pixels[pixel + 3] = 255;
    }
  }
  
      updatePixels();
      noLoop();
}